package com.byt.common.view.finder;

import android.content.Context;

import com.byt.base.preference.BasicDataPreferenceUtil;
import com.byt.base.utils.GsonUtils;
import com.byt.common.Constants;
import com.byt.common.view.finder.entity.Province;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by tom on 2018/3/21.
 */

public class AddressHelper {

    public static ArrayList<Province> getAddressProvice(Context context) {
       ArrayList<Province> data = new ArrayList<>();
        /* try {
            String json = ConvertUtils.toString(context.getAssets().open("city.json"));
            Gson mGson = new Gson();
            List<Province> list = mGson.fromJson(json, new TypeToken<List<Province>>() {
            }.getType());
            data.addAll(list);
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }*/
        ArrayList<Province> mData = null;
        try {
            mData =  GsonUtils.fromLocalJson(new JSONObject(BasicDataPreferenceUtil.getInstance().getString(Constants.ADDRESS_CASHE_XMXB)).getString("data"),
                    new TypeToken<ArrayList<Province>>() {}.getType());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (mData != null && mData.size() > 0) {
            data.addAll(mData);
        }
        return data;
    }
}